package com.dg.gaming.client.gui {
    import com.dg.gaming.api.common.util.Color;

    import flash.events.Event;

    import mx.containers.Canvas;

    public class TurnArrow extends Canvas {
        private var bgColor:Color;

        private var strokeColor:Color;

        private var reverse:Boolean;

        /**
         * Constructor which takes 2 colours.
         *
         * @param bgColor
         * @param strokeColor
         */
        public function TurnArrow(bgColor:Color, strokeColor:Color, reverse:Boolean) {
            this.bgColor = bgColor;
            this.strokeColor = strokeColor;
            this.reverse = reverse;
            this.width = 13;
            this.height = 15;
//            setStyle("backgroundColor", bgColor.getRGB());
            this.addEventListener("creationComplete", creationComplete);

        }

        public function creationComplete(evnt:Event):void {
            var arr:Array;
//            var arrY:Array;

            if (reverse) {
                arr = [[ 1, 7, 7, 12, 12, 7, 7 ], [ 7, 1, 5, 5, 10, 10, 13 ]];
            } else {
                arr = [[ 1, 6, 6, 12, 6, 6, 1 ], [ 5, 5, 1, 7, 13, 10, 10 ]];
            }
            graphics.clear();
            graphics.beginFill(bgColor.getRGB());
            var len:int = (arr[0] as Array).length;
            for (var i:int = 0; i < len; i++) {
                var x:int = arr[0][i];
                var y:int = arr[1][i];
                if (i == 0) {
                    graphics.moveTo(x, y);
                } else {
                    graphics.lineTo(x, y);
                }
            }
            graphics.endFill();
            if (reverse) {
                arr = [[ 0, 7, 7, 12, 12, 7, 7 ], [ 7, 0, 4, 4, 10, 10, 14 ]];
            } else {
                arr = [[ 0, 5, 5, 12, 5, 5, 0 ], [ 4, 4, 0, 7, 14, 10, 10 ]];
            }


            len = (arr[0] as Array).length;
            for (var j:int = 0; j < len; j++) {
                graphics.beginFill(strokeColor.getRGB());
                graphics.lineStyle(1);
                var x1:int;
                var y1:int;
                var x2:int;
                var y2:int;
                if (j == len - 1) {
                    x1 = arr[0][j];
                    y1 = arr[1][j];
                    x2 = arr[0][0];
                    y2 = arr[1][0];
                } else {
                    x1 = arr[0][j];
                    y1 = arr[1][j];
                    x2 = arr[0][j + 1];
                    y2 = arr[1][j + 1];
                }

                graphics.moveTo(x1, y1);
                graphics.lineTo(x2, y2);
                graphics.endFill();
            }

//		if (reverse) {
//                g.fillPolygon(new int[] {1, 7, 7, 12, 12, 7, 7},
//                              new int[] {7, 1, 5, 5, 10, 10, 13}, 7);
//            } else {
//                g.fillPolygon(new int[] {1, 6, 6, 12, 6, 6, 1},
//                              new int[] {5, 5, 1, 7, 13, 10, 10}, 7);
//            }
//        }


        }
    }
}